package com.zmn.plat.services.impl.service.tariff;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.zmn.plat.model.entity.service.tariff.ServiceTariff;
import com.zmn.plat.model.entity.service.tariff.ServiceTariffQuery;
import com.zmn.plat.persistence.interfaces.service.tariff.ServiceTariffDao;
import com.zmn.plat.services.interfaces.service.tariff.ServiceTariffService;

@Service
public class ServiceTariffServiceImpl implements ServiceTariffService {

    @Resource
    ServiceTariffDao faultTariffDao;

    @Override
    public ServiceTariff findByKey(Integer tariffId) {
        return faultTariffDao.findByKey(tariffId);
    }

    @Override
    @Cacheable(key = "'service:tariff:key:' + #p0", cacheNames = "redis1d")
    public ServiceTariff findByKeyWithCache(Integer tariffId) {
        return faultTariffDao.findByKey(tariffId);
    }

    @Override
    public ServiceTariff findByChannelIdAndBizTypeAndTariffType(Integer channelId, Integer keepType, Integer tariffType) {
        return faultTariffDao.findByChannelIdAndBizTypeAndTariffType(channelId, keepType, tariffType);
    }

    @Override
    public ServiceTariff findDefaultTariffByProductIdAndBizTypeAndTariffType(Integer productId, Integer keepType, Integer tariffType) {
        return faultTariffDao.findDefaultTariffByProductIdAndBizTypeAndTariffType(productId, keepType, tariffType);
    }

    @Override
    public ServiceTariff findByQuery(ServiceTariffQuery query) {
        return faultTariffDao.findByQuery(query);
    }

    @Override
    public List<ServiceTariff> listPageByQuery(ServiceTariffQuery query) {
        int count = countByQuery(query);
        query.setTotalCount(count);
        return faultTariffDao.listPageByQuery(query);
    }

    @Override
    public List<ServiceTariff> listByQuery(ServiceTariffQuery query) {
        return faultTariffDao.listByQuery(query);
    }

    @Override
    public List<ServiceTariff> findByKeys(List<Integer> ids) {
        return faultTariffDao.findByKeys(ids);
    }

    @Override
    @Cacheable(key = "'service:tariffall'", cacheNames = "redis1h")
    public List<ServiceTariff> listAll() {
        return faultTariffDao.listAll();
    }

    @Override
    public Integer countByQuery(ServiceTariffQuery query) {
        return faultTariffDao.countByQuery(query);
    }

    @Override
    public Integer findMaxSort() {
        return faultTariffDao.findMaxSort();
    }

    @Override
    public Integer updateStatusByKey(ServiceTariff faultTariff) {
        return faultTariffDao.updateStatusByKey(faultTariff);
    }

    @Override
    public Integer updateStatusBatchByKey(List<Integer> ids, Integer status, String mcStaffName) {
        return faultTariffDao.updateBatchStatusByKey(ids, status, mcStaffName);
    }

    @Override
    public Integer updateSortByKey(ServiceTariff faultTariff) {
        return faultTariffDao.updateSortByKey(faultTariff);
    }

    @Override
    public Integer updateSortByKey(Integer tariffId, Integer sort, String mcStaffName) {
        ServiceTariff faultTariff = new ServiceTariff();
        faultTariff.setTariffId(tariffId);
        faultTariff.setSort(sort);
        faultTariff.setUpdater(mcStaffName);
        faultTariff.setUpdateTime(new Date());

        return updateSortByKey(faultTariff);
    }

    @Override
    public Integer updateFirstLetterByKey(Integer tariffId, String firstLetter, String mcStaffName) {
        ServiceTariff faultTariff = new ServiceTariff();
        faultTariff.setTariffId(tariffId);
        faultTariff.setFirstLetter(firstLetter);
        faultTariff.setUpdater(mcStaffName);
        faultTariff.setUpdateTime(new Date());
        return faultTariffDao.updateFirstLetterByKey(faultTariff);
    }

    @Override
    public Integer updateByKey(ServiceTariff faultTariff) {
        return faultTariffDao.updateByKey(faultTariff);
    }

    @Override
    public Integer insert(ServiceTariff faultTariff) {
        return faultTariffDao.insert(faultTariff);
    }

    @Override
    public Integer deleteByKey(Integer tariffId) {
        return faultTariffDao.deleteByKey(tariffId);
    }

}